"""author: wenyao
   data: 2021/5/17
   project: devopscmdb
"""
# import math
# math.xx()

#python自省
#hasattr(math,"xx") 判断math有没有xx属性
#getattr(math,"xx") 获取math的xx属性
#setattr(math,"xx",obj)  设置math的xx属性位obj
#delattr(math,"xx")   删除math的xx属性
# import math
# if hasattr(math,"xx"):
#     math.xx()
# else:
#     print("math has no attribute xx")
#
class A:
    name = "sc"
    __max = "max"

    def func1(self):
        print("i am func1")

a = A()
# print(hasattr(a,"name"))

# if hasattr(a,"name"):
#     print(getattr(a,"name"))
#
# if hasattr(a,"func1"):
#     result = getattr(a,"func1")
#     result()

def func2():
    print("i am func2")

if not hasattr(a, "age"):
    setattr(a, "age", 18)
    setattr(a,"func2", func2)
    print(getattr(a,"age"))

# a.func2()
# if hasattr(a, "func2"):
#     delattr(a, "func2")
# a.func2()
